<template>
    <div>
      <Card class="clearfix" style="padding-bottom: 50px">
        <p slot="title">
            基础数据
        </p>

        <Row>
          <i-col span="24">
            <!-- 数据名称 -->
            <i-col span="3" >
                <Input  v-model="dataValue"  @on-change="searchDataValue" placeholder="字典数据" icon="search" style="width: 180px" />
            </i-col>
            <i-col span="3">
                <Button  @click="emptySearch" v-bind:style="{width: 90 + 'px' }" type="primary">清空检索</Button>
            </i-col>
        </i-col>
        </Row>

        <br>
            <Row class="margin-top-10 publish-button-con">
                <Button  @click="addData()" icon="ios-checkmark" v-bind:style="{ display:access.add, width: 90 + 'px' }" type="primary">新增</Button>
            </Row>
        <br>

        <div>
            <can-edit-table  @selectData="getSelectData" ref="canEditTable" v-model="tableData" :table-data="tableData" :access="access" v-on:delComplete="delComplete" ></can-edit-table>
        </div>
          <Page ref="pages" :total="recordCount" show-total style="float: right; margin-top: 20px" @on-change="searchMethod"></Page>
      </Card>
    </div>

</template>

<script>
import ajax from '../../../../libs/axios.js'
import canEditTable from './components/columnsTable.vue'
import {otherRouter} from '@/router/router'

export default {
    name: 'basicdataindex',
    components: {
        canEditTable
    },
    data () {
        return {
            // 权限设置
            access: {
                add:'none',
                edit: false,
                remove: false
            },
            typeId:'',
            pid:'',
            typeName:'',
            dataValue:'',
            tableData: [],
            recordCount: 0,
            showCurrentTableData: false,
            page: '',
            queryType:'' // 用于区分是从type表中还是从data变中查询上一级
        }
    },
    methods: {
        init () {
            let vm = this
            let edit = false
            let remove = false
            otherRouter.children.forEach(item => {
                if (item.name === 'updateBasicData') {
                    edit = true
                }
                if (item.name === 'addBasicData') {
                    vm.access.add = 'block'
                }
                if (item.name === 'removeSymptom') {
                    remove = true
                }
            })
            vm.access.edit = edit
            vm.access.remove = true
            // this.getOptionData()
            let typeId = this.$route.params.id
            vm.typeId = typeId

            let queryType = this.$route.params.queryType // 查询类型
            vm.queryType = queryType

            let pid = this.$route.params.pid // 父级id
            vm.pid = pid
            
            console.log("typeId:"+vm.typeId)
            this.searchMethod(1,typeId)
        },
        // 新增
        addData () {
            console.log('添加症状数据')
            let vm = this
            let typeId = vm.typeId
            let pid = vm.pid
            let argu = {
                pid: pid,
                typeId: typeId,
                queryType:vm.queryType
            }
            vm.$router.push({
                name: 'addBasicData',
                params: argu
            })
        },
        emptySearch () {
            this.dataValue = ''
        },
        //检索字典数据
        searchDataValue(){
            this.searchMethod(1)
        },
        // 检索方法
        searchMethod (page, typeId) {
            let url = '/adminapi/basicdata/basicDataList.html'
            let data = {
                dataValue: this.dataValue,
                typeId: this.typeId,
                queryType: this.queryType,
                pageNumber: page,
                pageSize: 10
            }
            ajax.jsonRes(url, data).then(res => {
                // success
                console.log("***********")
                console.log(res)
                this.tableData = res.list
                this.recordCount = res.recordCount
            }).catch(res => {
                // fail
                console.log('获取症状数据有错误信息')
            })
        },
        getSelectData : function (typeId) {
            console.log("getSelectData方法接受子组件传过来的值："+typeId)
            this.pid = this.typeId
            this.typeId=typeId; // 给typeId赋值接受到的数据
            this.queryType = 'data'
            this.searchMethod(1,typeId)
        },
        delComplete () {
            this.searchMethod(1)
        }
    },
    created () {
        this.init()
    },
    // created 进入页面初始化一次    activated每次进入页面都初始化
    activated () {
        this.init()
    }
}
</script>
